home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / GNUUCP_2 / SOURCE / PACKET_D.MS < prev    next >
Text File  |  1989-07-31  |  14KB  |  557 lines

  1. .\" @(#) packet.driver.ms    Version hoptoad-1.3    87/03/24
  2. .\"
  3. .\" format this with [nt]roff -ms.
  4. .\"
  5. .\" From: greg@sgi.uucp (Greg Chesson)
  6. .\" Newsgroups: mod.std.unix
  7. .\" Volume-Number: Volume 9, Number 55
  8. .\" Subject: Packet Driver Protocol
  9. .\" Message-ID: <7136@ut-sally.UUCP>
  10. .\" Date: 11 Feb 87 23:44:09 GMT
  11. .\"
  12. .\" This message contains a copy of ``Packet Driver Protocol,''
  13. .\" written by G. L. Chesson while he was at Bell Laboratories.
  14. .\" He remarks that it was approved for public distribution, and that
  15. .\" 
  16. .\"     The version of the note that you probably have omits the
  17. .\"     detail that the transmitted checksum is really 0125252
  18. .\"     - the block checksum function.
  19. .\" 
  20. .\" [Note that 0125252 is 0xAAAA, which is easier to remember.
  21. .\" I have folded this update into the document. -- hoptoad!gnu]
  22. .ce
  23. .B
  24. Packet Driver Protocol
  25. .R
  26. .sp 1
  27. .ce
  28. G. L. Chesson
  29. .br
  30. .ce
  31. Bell Laboratories
  32. .SH
  33. Abstract
  34. .in +.5i
  35. .PP
  36. These notes describe the packet driver link
  37. protocol that was supplied
  38. with the
  39. Seventh Edition of
  40. .UX
  41. and is used by the UUCP program.
  42. .in -.5i
  43. .SH
  44. General
  45. .PP
  46. Information flow between a pair of machines
  47. may be regulated by
  48. first
  49. representing the data 
  50. as sequence-numbered 
  51. .I
  52. packets
  53. .R
  54. of data 
  55. and then establishing conventions that
  56. govern the use of sequence numbers.
  57. The
  58. .I
  59. PK,
  60. .R
  61. or
  62. .I
  63. packet driver,
  64. .R
  65. protocol
  66. is a particular instance of this type of
  67. flow-control discipline.
  68. The technique depends on the notion of a transmission
  69. .I
  70. window
  71. .R
  72. to determine upper and lower bounds for valid
  73. sequence numbers.
  74. The transmitter is allowed to retransmit packets
  75. having sequence numbers
  76. within the window until the receiver indicates that
  77. packets have been correctly received.
  78. Positive acknowledgement from the receiver moves the
  79. window;
  80. negative acknowledgement or no acknowledgement
  81. causes retransmission.
  82. The receiver must ignore duplicate transmission, detect
  83. the various errors that may occur,
  84. and inform the transmitter when packets are 
  85. correctly or incorrectly received.
  86. .PP
  87. The following paragraphs describe the packet formats,
  88. message exchanges,
  89. and framing
  90. used by the protocol as coded
  91. in the UUCP program and the
  92. .UX
  93. kernel.
  94. Although no attempt will be made here to present
  95. internal details of the algorithms that were used,
  96. the checksum routine is supplied
  97. for the benefit of other implementors.
  98. .SH
  99. Packet Formats
  100. .PP
  101. The protocol is defined in terms of message
  102. transmissions of 8-bit bytes.
  103. Each message includes one
  104. .I
  105. control
  106. .R
  107. byte plus a
  108. .I
  109. data segment
  110. .R
  111. of zero or more information bytes.
  112. The allowed data segment sizes range
  113. between 32 and 4096 as determined by the formula
  114. 32(2\uk\d) where
  115. k is a 3-bit number.
  116. The packet sequence numbers are likewise constrained
  117. to 3-bits; i.e. counting proceeds modulo-8.
  118. .PP
  119. The control byte is partitioned into three fields as
  120. depicted below.
  121. .bp
  122. .nf
  123. .sp 
  124. .in 1i
  125. .ls 1
  126. bit    7    6    5    4    3    2    1    0
  127.     t    t    x    x    x    y    y    y
  128. .ls 1
  129. .in -1i
  130. .fi
  131. .sp
  132. The
  133. .I
  134. t
  135. .R
  136. bits indicate a packet type and
  137. determine the interpretation to be placed on
  138. the
  139. .I
  140. xxx
  141. .R
  142. and
  143. .I
  144. yyy
  145. .R
  146. fields.
  147. The various interpretations are as follows:
  148. .in +1i
  149. .sp
  150. .nf
  151. .ls 1
  152. .I
  153. tt    interpretation
  154. .sp
  155. .R
  156. 00    control packet
  157. 10    data packet
  158. 11    `short' data packet
  159. 01    alternate channel
  160. .ls 1
  161. .fi
  162. .sp
  163. .in -1i
  164. A data segment accompanies all non-control packets.
  165. Each transmitter is constrained to observe the maximum
  166. data segment size
  167. established during initial synchronization by the
  168. receiver that it sends to.
  169. Type 10 packets have maximal size data segments.
  170. Type 11, or `short', packets have zero or more data
  171. bytes but less than the maximum.
  172. The first one or two bytes of the data segment of a
  173. short packet are `count' bytes that
  174. indicate the difference between the
  175. maximum size and the number of bytes in the short
  176. segment.
  177. If the difference is less than 127, one count
  178. byte is used.
  179. If the difference exceeds 127,
  180. then the low-order seven bits of the difference
  181. are put in the first data byte and the high-order
  182. bit is set as an indicator that the remaining
  183. bits of the difference are in the second byte.
  184. Type 01 packets are never used by UUCP
  185. and need not be discussed in detail here.
  186. .PP
  187. The sequence number of a non-control packet is
  188. given by the
  189. .I
  190. xxx
  191. .R
  192. field.
  193. Control packets are not sequenced.
  194. The newest sequence number,
  195. excluding duplicate transmissions,
  196. accepted by a receiver is placed in the
  197. .I
  198. yyy
  199. .R
  200. field of non-control packets sent to the
  201. `other' receiver.
  202. .PP
  203. There are no data bytes associated with a control packet,
  204. the
  205. .I
  206. xxx
  207. .R
  208. field is interpreted as a control message,
  209. and the
  210. .I
  211. yyy
  212. .R
  213. field is a value accompanying the control message.
  214. The control messages are listed below in decreasing priority.
  215. That is, if several control messages are to be sent,
  216. the lower-numbered ones are sent first.
  217. .in +1i
  218. .nf
  219. .ls 1
  220. .sp
  221. .I
  222. xxx    name        yyy
  223. .R
  224.  
  225. 1    CLOSE    n/a
  226. 2    RJ        last correctly received sequence number
  227. 3    SRJ        sequence number to retransmit
  228. 4    RR        last correctly received sequence number
  229. 5    INITC    window size
  230. 6    INITB    data segment size
  231. 7    INITA    window size
  232. .in -i
  233. .ls 1
  234. .fi
  235. .sp
  236. .PP
  237. The CLOSE message indicates that the communications channel
  238. is to be shut down.
  239. The RJ, or
  240. .I
  241. reject,
  242. .R
  243. message indicates that the receiver has detected an error
  244. and the sender should retransmit after using the 
  245. .I
  246. yyy
  247. .R
  248. field to update the window.
  249. This mode of retransmission is usually
  250. referred to as a
  251. `go-back-N' procedure.
  252. The SRJ, or
  253. .I
  254. selective reject,
  255. .R
  256. message carries with it the sequence number of
  257. a particular packet to be retransmitted.
  258. The RR, or
  259. .I
  260. receiver ready,
  261. .R
  262. message indicates that the receiver has detected
  263. no errors; the
  264. .I
  265. yyy
  266. .R
  267. field updates the sender's window.
  268. The INITA/B/C messages are used
  269. to set window and data segment sizes.
  270. Segment sizes are calculated by the formula
  271. 32(2\uyyy\d)
  272. as mentioned above,
  273. and window sizes may range between 1 and 7.
  274. .PP
  275. Measurements of the protocol running on communication
  276. links at rates up to 9600 baud showed that
  277. a window size of 2 is optimal
  278. given a packet size greater than 32 bytes.
  279. This means that the link bandwidth can be fully utilized
  280. by the software.
  281. For this reason the SRJ message is not as important as it
  282. might otherwise be.
  283. Therefore the
  284. .UX
  285. implementations no longer generate or respond to SRJ
  286. messages.
  287. It is mentioned here for historical accuracy only,
  288. and one may assume that SRJ is no longer part of the protocol.
  289. .SH
  290. Message Exchanges
  291. .SH
  292.     Initialization
  293. .PP
  294. Messages are exchanged between four cooperating
  295. entities: two senders and two receivers.
  296. This means that the communication channel is thought of
  297. as two independent half-duplex data paths.
  298. For example the window and segment sizes need not
  299. be the same in each direction.
  300. .PP
  301. Initial synchronization is accomplished
  302. with two 3-way handshakes: two each of
  303. INITA/INITB/INITC.
  304. Each sender transmits INITA messages repeatedly.
  305. When an INITA message is received, INITB is
  306. sent in return.
  307. When an INITB message is received
  308. .I
  309. and
  310. .R
  311. an INITB message has been sent,
  312. an INITC message is sent.
  313. The INITA and INITB messages carry 
  314. with them the packet and window size that
  315. each receiver wants to use,
  316. and the senders are supposed to comply.
  317. When a receiver has seen all three
  318. INIT messages, the channel is 
  319. considered to be open.
  320. .PP
  321. It is possible to design a protocol that starts up using
  322. fewer messages than the interlocked handshakes described above.
  323. The advantage of the more complicated design lies in its use as
  324. a research vehicle:
  325. the initial handshake sequence is completely symmetric,
  326. a handshake
  327. can be initiated by one side of the link while the
  328. connection is in use, and the software to do this can
  329. utilize code that would ordinarily be used only once
  330. at connection setup time.
  331. These properties were used in experiments with dynamically
  332. adjusted parameters.
  333. That is attempts were made to adapt the window and segment
  334. sizes to changes observed in traffic while a link was in use.
  335. Other experiments used the initial
  336. handshake  in a different way
  337. for restarting the protocol without data loss
  338. after machine crashes.
  339. These experiments never worked well in the packet driver and
  340. basically provided the impetus for other protocol designs.
  341. The result 
  342. as far as UUCP is concerned is that initial synchronization
  343. uses the two 3-way handshakes, and the INIT
  344. messages are ignored elsewhere.
  345. .SH
  346.     Data Transport
  347. .PP
  348. After initial synchronization each receiver
  349. sets a modulo-8 incrementing counter R to 0;
  350. each sender sets a similar counter S to 1.
  351. The value of R is always the number of the most recent
  352. correctly received packet.
  353. The value of S is always the first sequence number in
  354. the output window.
  355. Let W denote window size.
  356. Note that the value of W may be different for each sender.
  357. .PP
  358. A sender may transmit packets with sequence numbers
  359. in the range S to (S+W-1)\ mod-8.
  360. At any particular time a receiver expects
  361. arriving packets to have numbers in the range
  362. (R+1)\ mod-8 to (R+W)\ mod-8.
  363. Packets must arrive in sequence number order
  364. are are only acknowledged in order.
  365. That is,
  366. the `next' packet a receiver
  367. will acknowledge must have
  368. sequence number (R+1)\ mod-8.
  369. .PP
  370. A receiver acknowledges receipt of data packets
  371. by arranging for the value of its R counter to be
  372. sent across the channel
  373. where it will be used to update an S counter.
  374. This is done in two ways.
  375. If data is flowing in both directions across a
  376. channel then each receiver's current R value is
  377. carried in the
  378. .I
  379. yyy
  380. .R
  381. field of non-control packets.
  382. Otherwise when there is no bidirectional
  383. data flow,
  384. each receiver's R value is transmitted across the link
  385. as the
  386. .I
  387. yyy
  388. .R
  389. field of an RR control packet.
  390. .PP
  391. Error handling is up to the discretion
  392. of the receiver.
  393. It can ignore all errors in which case
  394. transmitter timeouts must provide for
  395. retransmission.
  396. The receiver may also generate RJ 
  397. error control packets.
  398. The
  399. .I
  400. yyy
  401. .R
  402. field of an incoming RJ message replaces
  403. the S value of the local sender and
  404. constitutes a request for retransmission to start
  405. at that sequence number.
  406. The
  407. .I
  408. yyy
  409. .R
  410. field of an incoming SRJ message selects a particular
  411. packet for retransmission.
  412. .PP
  413. The resemblance between the flow control procedure in the
  414. packet driver and that defined for X.25 is no accident.
  415. The packet driver protocol began life as an attempt at
  416. cleaning up X.25.
  417. That is why, for example,
  418. control information is uniform in length (one byte),
  419. there is no RNR message (not needed),
  420. and there is but one timeout defined
  421. in the sender.
  422. .SH
  423.     Termination
  424. .PP
  425. The CLOSE message is used to terminate communications.
  426. Software on either or both ends of the communication
  427. channel may initiate termination.
  428. In any case when one end wants to terminate it sends
  429. CLOSE messages until one is received from the other end
  430. or until a programmable limit on the number of CLOSE
  431. messages is reached.
  432. Receipt of a CLOSE message causes a CLOSE message to be sent.
  433. In the 
  434. .UX
  435. environment
  436. it also causes the SIGPIPE or
  437. `broken pipe' signal to be sent to
  438. the local process using the communication channel.
  439. .SH
  440.     Framing
  441. .PP
  442. The term
  443. .I
  444. framing
  445. .R
  446. is used to denote the technique by which the
  447. beginning and end of a message is detected
  448. in a byte stream;
  449. .I
  450. error control
  451. .R
  452. denotes the method by which transmission
  453. errors are detected.
  454. Strategies for framing and error control depend
  455. upon
  456. additional information being transmitted along
  457. with the control byte and data segment,
  458. and the choice of a particular strategy usually
  459. depends on characteristics of input/output
  460. devices and transmission media.
  461. .PP
  462. Several framing techniques are in used in support
  463. of PK protocol implementations,
  464. not all of which can be described in detail here.
  465. The technique used on asynchronous serial lines
  466. will be described.
  467. .PP
  468. A six byte
  469. framing
  470. .I
  471. envelope
  472. .R
  473. is constructed using the control byte
  474. C of a packet and five other bytes as
  475. depicted below.
  476. .in +1i
  477. <DLE><k><c0><c1><C><x>
  478. .in -1i
  479. The <DLE> symbol denotes the ASCII ctrl/P character.
  480. If the envelope is to be followed by a data segment,
  481. <k> has the value
  482. log\d2\u(size)-4;
  483. i.e. 1 \(<= k \(<= 8.
  484. If k is 9, then the envelope represents a control packet.
  485. The <c0> and <c1> bytes are the low-order and high-order
  486. bytes respectively of 0xAAAA minus a 16-bit checksum.
  487. For control packets, this 16-bit checksum is the same
  488. as the control byte C.
  489. For data packets, the checksum is calculated by the 
  490. program below.
  491. The <x> byte is the exclusive-or of <k><c0><c1><C>.
  492. Error control is accomplished by checking 
  493. a received framing envelope for compliance with the definition,
  494. and comparing a checksum function of the data segment
  495. with <c0><c1>.
  496. .PP
  497. This particular framing strategy assumes data segments
  498. are constant-sized:
  499. the `unused' bytes in a short packet are actually
  500. transmitted.
  501. This creates a certain amount of overhead which
  502. can be eliminated by a more complicated framing technique.
  503. The advantage of this strategy is that i/o
  504. devices can be programmed to take advantage of the
  505. constant-sized framing envelopes and data segments.
  506. .bp
  507. .PP
  508. The checksum calculation is displayed below as a C function.
  509. Note that the code is not truly portable because
  510. the definitions of
  511. .I short
  512. and
  513. .I char
  514. are not necessarily uniform across all machines
  515. that might support this language.
  516. This code assumes that
  517. .I short
  518. and
  519. .I char
  520. are 16 and 8-bits respectively.
  521. .PP
  522. .in +.5i
  523. .nf
  524. .ft CW
  525. .ls 1
  526. /* [Original document's version corrected to actual version] */
  527. chksum(s,n)
  528. register char *s;
  529. register n;
  530. {
  531.     register short sum;
  532.     register unsigned short t;
  533.     register short x;
  534.  
  535.     sum = -1;
  536.     x = 0;
  537.  
  538.     do {
  539.         if (sum<0) {
  540.             sum <<= 1;
  541.             sum++;
  542.         } else
  543.             sum <<= 1;
  544.         t = sum;
  545.         sum += (unsigned)*s++ & 0377;
  546.         x += sum^n;
  547.         if ((unsigned short)sum <= t) {
  548.             sum ^= x;
  549.         }
  550.     } while (--n > 0);
  551.  
  552.     return(sum);
  553. }
  554. .fi
  555. .in -.5i
  556. .ft R
  557.